package com.unhz.generator.pojo;

/**
 * @Author: 沈佳庆
 * @Description:
 * @Date: Created in 下午 5:17 2018/1/29 0029
 * @Modified By:
 */
public class Node {

    public String id;

    public String name;

    public String text;

    public String parentId;

    private Children children = new Children();

    // 先序遍历，拼接JSON字符串
    public String toString() {
        String result = "{"
                + "id : '" + id + "'"
                + ", text : '" + text + "'"
                + ", name : '" + name + "'";

        if (children != null && children.getSize() != 0) {
            result += ", children : " + children.toString();
        } else {
            result += ", leaf : true";
        }

        return result + "}";
    }

    // 兄弟节点横向排序
    public void sortChildren() {
        if (children != null && children.getSize() != 0) {
            children.sortChildren();
        }
    }

    // 添加孩子节点
    public void addChild(Node node) {
        this.children.addChild(node);
    }
}
